<!doctype html public "-//w3c//dtd html 4.0 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<?php
$this->load->view("head");
?>

<!--The following scripts and css inclueded are used specifically for register-->
<script language="javascript" src="<?php echo base_url();?>js/jquery/school.js"></script>
<script src="<?php echo base_url(); ?>js/formValidator/jquery_last.js" type="text/javascript"></script>
<link type="text/css" rel="stylesheet" href="<?php echo base_url(); ?>js/formValidator/style/validator.css" />
<script src="<?php echo base_url(); ?>js/formValidator/formValidator_min.js" type="text/javascript"></script>
<script src="<?php echo base_url(); ?>js/formValidator/formValidatorRegex.js" type="text/javascript"></script>
<script type="text/javascript">
           $(document).ready(function(){
                $.formValidator.initConfig({onError:function(msg){alert(msg)}});
                $("#isbn10").formValidator({tipid:"v_isbn10",onempty:"10位ISBN不能为空",onshow:"请输入10位ISBN，比如0131101633",onfocus:"只输入数字"}).InputValidator({min:10,max:10,onerror:"请确保10位或13位ISBN至少输入一个；或者您输入的ISBN错误"}).RegexValidator({regexp:"[0-9]",onerror:"ISBN只能包含阿拉伯数字"}).AjaxValidator({type:"get",url:"<?php echo site_url();?>/book/is_isbn10_usable",data:'/'+$("#isbn10").val(),datatype:"html",success:function(msg){if(escape(msg)=="0") {return true;}else{return false;}},error: function(){alert("服务器没有返回数据，可能服务器忙，请重试");},onerror : "数据库中已经有这个ISBN对应的图书，请用ISBN进行搜索",onwait : "正在对ISBN进行校验，请稍候..."});
                $("#isbn13").formValidator({tipid:"v_isbn13",onempty:"13位ISBN不能为空",onshow:"请输入13位ISBN，比如9780131131630",onfocus:"只输入数字"}).InputValidator({min:13,max:13,onerror:"请确保10位或13位ISBN至少输入一个；或者您输入的ISBN错误"}).RegexValidator({regexp:"[0-9]",onerror:"ISBN只能包含阿拉伯数字"}).AjaxValidator({type:"get",url:"<?php echo site_url();?>/book/is_isbn13_usable",data:'/'+$("#isbn13").val(),datatype:"html",success:function(msg){if(escape(msg)=="0") {return true;}else{return false;}},error: function(){alert("服务器没有返回数据，可能服务器忙，请重试");},onerror : "数据库中已经有这个ISBN对应的图书，请用ISBN进行搜索",onwait : "正在对ISBN进行校验，请稍候..."});
                $("#title").formValidator({tipid:"v_title",onempty:"书名不能为空",onshow:"请输入书名，英文图书请同时输入中文和英文名",onfocus:"请输入书名，英文图书请同时输入中文和英文名"}).InputValidator({min:1,max:50,onerror:"您输入的书名长度错误"});
                $("#author").formValidator({tipid:"v_author",onempty:"作者名不能为空",onshow:"请输入作者名",onfocus:"请输入作者名，多个作者以逗号隔开"}).InputValidator({min:1,max:30,onerror:"您输入的作者名长度错误"});
                $("#publisher").formValidator({tipid:"v_publisher",onempty:"出版社名不能为空",onshow:"请输入出版社名称",onfocus:"请输入出版社名称"}).InputValidator({min:1,max:30,onerror:"您输入的出版社名长度错误"});
                $("#pages").formValidator({tipid:"v_pages",onempty:"页数不能为空",onshow:"请输入书籍页数",onfocus:"请输入书籍页数"}).InputValidator({min:1,max:5,onerror:"您输入的页码长度错误"}).RegexValidator({regexp:"[0-9]",onerror:"只能包含数字"});
                $("#year").formValidator({tipid:"v_year",onempty:"出版年份不能为空",onshow:"请输入四位出版年份",onfocus:"请输入四位年份"}).InputValidator({min:4,max:4,onerror:"您输入的年份长度错误"}).RegexValidator({regexp:"[0-9]",onerror:"只能包含数字"});
                $("#month").formValidator({tipid:"v_month",onempty:"出版月份不能为空",onshow:"请输入两位出版月份，不足两位前面补零",onfocus:"请输入四位月份"}).InputValidator({min:2,max:2,onerror:"您输入的月份长度错误"}).RegexValidator({regexp:"[0-9]",onerror:"只能包含数字"});
                $("#edition").formValidator({tipid:"v_edition",onempty:"版本不能为空",onshow:"请输入图书版本",onfocus:"请输入图书版本"}).InputValidator({min:1,max:2,onerror:"您输入的版本长度错误"}).RegexValidator({regexp:"[0-9]",onerror:"只能包含数字"});
            });
</script>

</head>

<?php
$this->load->view("headview");
?>


<?php
    function printArray($elements) {
    $result = '';
    foreach ($elements as $element) {
      if (!empty($result)) $result = $result.', ';
      $result = $result.$element;
    }
    return $result;
    }

    if($feed==null)
        $entry=null;
    else
        $entry=$feed[0];
    $title="";
    $isbn="";
    $isbn10="";
    $isbn13="";
    $publisher="";
    $date="";
    $page="";
    $language="";
    $volumeId="";
    $creators="";
    $thumbnail_img="";
    $thumbnail="";

    if($entry!=null){        
        $title = printArray($entry->getTitles());
        $isbn=printArray($entry->getIdentifiers());
        $isbns=explode(",",$isbn);
        if(count($isbns)==3){
            $isbn10=$isbns[1];
            $isbn10=substr($isbn10,6);  //从 ISBN:后面开始截取
            $isbn13=$isbns[2];
            $isbn13=substr($isbn13,6);
        }
        elseif(count($isbns)==2){
            $isbn13=$isbns[1];
            $isbn13=substr($isbn13,6);
        }
        else{
            $isbn10="";
            $isbn13="";
        }

        $publisher= printArray($entry->getPublishers());
        $date= printArray($entry->getDates());
        $page= printArray($entry->getFormats());
        $pages=explode(" ",$page);
        $page=$pages[0];
        $language= printArray($entry->getLanguages());
        $volumeId = $entry->getVolumeId();
        if ($thumbnailLink = $entry->getThumbnailLink()) {
            $thumbnail = $thumbnailLink->href;
        } else {
            $thumbnail = null;
        }
        $creators = printArray($entry->getCreators());
        $thumbnail_img = (!$thumbnail) ? '' : '<img src="'.$thumbnail.'"/>';
    }
?>


<div class="center_chart">
<h2>添加书籍</h2>
添加一本书籍，将获得100积分，帮助其他用户简化买卖流程。<br />
ISBN至少填写一个。带星号的项必填。
<?php if($error!="none") echo "<font color=\"#FF0000\">$error</font>"?>
<form name="addbook_form" id="addbook_form" enctype="multipart/form-data" method="post" action="<?=site_url()?>/book/do_addbook">
    <?=$thumbnail_img?>
    <div class="form_row">
    <label class="contact">10位ISBN</label>
	<input name="isbn10"  type="text" id="isbn10" class="contact_input" value="<?=$isbn10?>"/>
    </div><br />
    <div id="v_isbn10" align="left"></div>

    <div class="form_row">
	<label class="contact">13位ISBN</label>
	<input name="isbn13"  type="text" id="isbn13" class="contact_input" value="<?=$isbn13?>" />
    </div><br />
    <div id="v_isbn13" align="left"></div>

     <div class="form_row">
	<label class="contact">书名</label>
	<input name="title"  type="text" id="title" class="contact_input" value="<?=$title?>"/><font color="red" size="3">*</font>
    </div><br />   
    <div id="v_title" align="left"></div>

    <div class="form_row">
	<label class="contact">作者</label>
	<input name="author"  type="text" id="author" class="contact_input" value="<?=$creators?>"/><font color="red" size="3">*</font>
    </div><br />
    <div id="v_author" align="left"></div>

    <div class="form_row">
	<label class="contact">出版社</label>
	<input name="publisher"  type="text" id="publisher" class="contact_input" value="<?=$publisher?>"/><font color="red" size="3">*</font>
    </div><br />
    <div id="v_publisher" align="left"></div>

    <div class="form_row">
	<label class="contact">英文书名</label>
	<input name="en_title"  type="text" id="en_title" class="contact_input" />
    </div><br />
    <div id="v_title" align="left"></div>

     <div class="form_row">
         <input type="hidden" name="site_url" id="site_url" value="<?=site_url()?>">
        <label class="contact">一级分类</label>
        <select name="category_1" id="category_1" onchange="listcategorys(this.value)">
            <option value="0">请选择</option>
            <option value="1">计算机与网络</option><option value="2">经济管理</option>
            <option value="3">外语</option><option value="4">教育</option>
      <!--      <option value="0">其他</option><option value="0">生活</option> -->
            <option value="7">文学</option><option value="5">人文社科</option>
            <option value="9">科学与自然</option><option value="10">小说</option>
            <option value="11">文化</option><option value="12">医学</option>
            <option value="13">数学</option><option value="14">青春</option>
        </select>
        <label class="contact">二级分类</label>
        <select name="category_2" id="category_2"><option value="0">请选择</option></select>
    </div><br/>
    



    <div class="form_row">
	<label class="contact">版本</label>
    <select name="edition" id="edition" class="contact_input" >
    <?php for($i=13;$i>0;$i--){ ?>
              <option value="<?=$i?>" selected="selected"><?=$i?></option>;
     <?php } ?>
     </select>
    </div><br />

    <div class="form_row">
	<label class="contact">语言</label>
    <select name="language" id="language" class="contact_input" >
           <option value="cn" selected="selected">中文</option>
           <option value="en">英文</option>
     </select>
    </div><br />

    <div class="form_row">
	<label class="contact">页数</label>
	<input name="pages"  type="text" id="pages" class="contact_input" value="<?=$page?>"/>
    </div><br />
    <div id="v_pages" align="left"></div>

    <div class="form_row">
	<label class="contact">出版时间</label>
	<select name="year" id="year" class="contact_input" value="<?=$date?>">
    <?php for($i=1970;$i<2010;$i++){ ?>
              <option value="<?=$i?>" selected="selected"><?=$i?></option>;
     <?php } ?>
     </select>
	<select name="month" id="month" class="contact_input" >
    <?php for($i=1;$i<13;$i++){ ?>
              <option value="<?=$i?>" selected="selected"><?=$i?></option>;
     <?php } ?>
     </select>
    </div><br />

    <div class="form_row">
	<label class="contact">标价</label>
	<input name="price"  type="text" id="price" class="contact_input" />
    </div><br />
    <div id="v_price" align="left"></div>


    <?php if($thumbnail_img==""){?>
    <div class="form_row">
	<label class="contact">上传书籍封面图片</label>
	<input type="file" name="userfile" size="20" />
    </div><br />
    <div id="v_upload" align="left"></div>
    <input type="hidden" name="imagelink" value="<?=null;?>">
    <?php }
       else{ ?>
    <input type="hidden" name="imagelink" value="<?=$thumbnail;?>">
    <?php }?>
    <div class="form_row">
	<input  id="submit_button"  type="submit" value="提交"  />
    </div>
  </form>
</div><!-- end of center content --><!-- end of right content -->
<?php
$this->load->view("footer");
?>